﻿
function initmymmall() {
    $("#myFilterBtn").live("click", function () {
        $("#divmymFilter").toggle('fast');
    });
};
initmymmall();

function initschListBtn() {
    $(".schListBtn").click(function () {
        var _self = $(this);
        if (_self.hasClass("schListBtn-type1")) {
            _self.removeClass("schListBtn-type1").addClass("schListBtn-type2");
            $("#J_ItemList").removeClass("album").addClass("list");
        } else {
            _self.removeClass("schListBtn-type2").addClass("schListBtn-type1");
            $("#J_ItemList").removeClass("list").addClass("album");
        }
    });
};
initschListBtn();

function GetChangeArea(htmlWrap, parentId, itemId, IsHasAll, IsChangeCountry) {
    GtGrid1Action = "GetChangedArea";
    var opart = new jsonRow();
    opart.AddCell("ACTION", GtGrid1Action);
    opart.AddCell("controlWrap", htmlWrap);
    opart.AddCell("parentId", parentId);
    opart.AddCell("controlId", itemId);
    opart.AddCell("IsHasAll", IsHasAll);

    if (IsChangeCountry) {
        ajaxComm(opart, null, function () {
            var cityId = $("#citySel").val();
            $("#city").val(cityId);
            GetChangeArea("desWrap", cityId, "destinationSel", "Y", false);
        });
    }
    else {
        ajaxComm(opart);
    }

}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return r[2]; return null;
}

function GetVehicleListInfo() {
    GtGrid1Action = "loadVehiclelistdata";
    var opart = new jsonRow();
    opart.AddCell("ACTION", GtGrid1Action);
    opart.AddCell("f", GetQueryString("f"));
    opart.AddCell("page", GetQueryStr("page"));
    opart.AddCell("country", GetQueryStr("country"));
    opart.AddCell("des", GetQueryStr("des"));
    opart.AddCell("vtype", GetQueryStr("vtype"));
    opart.AddCell("brand", GetQueryStr("brand"));
    opart.AddCell("stype", GetQueryStr("stype"));
    opart.AddCell("vprice", GetQueryStr("vprice"));
    opart.AddCell("seats", GetQueryStr("seats"));
    ajaxComm(opart);
}

var goodslisttemphtml = "";
function doBoundGoodsList(_data, queryStr, searchVal) {
    if (goodslisttemphtml && goodslisttemphtml != "") {
        laytpl(goodslisttemphtml).render(_data, function (render) {
            $("#J_ItemList").html(render);
        });
    } else {
        jQuery.loadHtml("/mMall/Template/mSysGoodsSearchList.html").done(function (_rethtml) {
            goodslisttemphtml = HtmlUtil.htmlDecode(_rethtml);
            laytpl(goodslisttemphtml).render(_data, function (render) {
                $("#J_ItemList").html(render);
            });
        });
    }
    $("#txtQuery").val(queryStr);
    $("#f").val(searchVal);
    $("#datacurrpage").val(_data.page);
    createPaging('J_trade_pagenation', _data.page, _data.total, function (_topagenum) { doToPageNm(_topagenum); });
};

function doToPageNm(_pNum) {
    var sortt = "";
    if ($(".fSort .fSort-cur").length > 0) {
        sortt = $(".fSort .fSort-cur").attr("sort-data") + " " + $(".fSort .fSort-cur").attr("sort-upd");
    }

    window.location.href = '/mp_VehicleList.htm?' + $("#txtQuery").val()
+ "&page=" + (_pNum || $("#datacurrpage").val())
+ "&sort=" + sortt;

};

var goodsListData = "";

function setFilterCondition() {
    $("#vehicleType").change(function () {
        $("#vtype").val($(this).val());
        $(".btn-home-search").click();
    })

    $("#vehicleBrand").change(function () {
        $("#brand").val($(this).val());
        $(".btn-home-search").click();
    })

    $("#vehiclePrice").change(function () {
        $("#vprice").val($(this).val());
        $(".btn-home-search").click();
    })

    $("#vehicleSeats").change(function () {
        $("#seats").val($(this).val());
        $(".btn-home-search").click();
    })

    $("#serviceType").change(function () {
        $("#stype").val($(this).val());
        $(".btn-home-search").click();
    })

    $("#countrySel").live("change", function () {
        var countryId = $(this).val();
        requestAreaInfo(countryId, "", true, true);
        $("#country").val(countryId);
        $("#des").val("0");
    })

    $("#citySel").live("change", function () {
        var cityId = $(this).val();
        $("#city").val(cityId);
        $("#des").val("0");
        requestAreaInfo("", cityId, false, true);
        $(".btn-home-search").click();
    })

    $("#destinationSel").live("change", function () {
        var desId = $(this).val();
        $("#des").val(desId);
        $(".btn-home-search").click();
    })
}
setFilterCondition();

function initQueryParm(isReLoad) {
    if (!isReLoad) {
        var country = GetQueryStr("country") == "" ? "DF6723BE-A25C-4F77-BB49-A1662D3E6F2A" : GetQueryStr("country");
        $("#country").val(country);
        $("#countrySel").val(country);

        var city = GetQueryStr("city") == "" ? "AEF39D8E-D298-4AF1-AEC5-2B00D237F5F5" : GetQueryStr("city");
        $("#city").val(city);
        $("#citySel").val(city);

        var des = GetQueryStr("des");
        $("#des").val(des);
        $("#destinationSel").val(des);

    }
    var vtype = GetQueryStr("vtype") == "" ? "0" : GetQueryStr("vtype");
    $("#vtype").val(vtype);
    $("#vehicleType").val(vtype);

    var brand = GetQueryStr("brand") == "" ? "0" : GetQueryStr("brand");
    $("#brand").val(brand);
    $("#vehicleBrand").val(brand);

    var vprice = GetQueryStr("vprice") == "" ? "0|0" : GetQueryStr("vprice");
    $("#vprice").val(vprice);
    $("#vehiclePrice").val(vprice);

    var seats = GetQueryStr("seats") == "" ? "0|0" : GetQueryStr("seats");
    $("#seats").val(seats);
    $("#vehicleSeats").val(seats);

    var stype = GetQueryStr("stype") == "" ? "0" : GetQueryStr("stype");
    $("#stype").val(stype);
    $("#serviceType").val(stype);
}

function InitAreaInfo() {
    var country = GetQueryStr("country") == "" ? "DF6723BE-A25C-4F77-BB49-A1662D3E6F2A" : GetQueryStr("country");
    var city = GetQueryStr("city") == "" ? "AEF39D8E-D298-4AF1-AEC5-2B00D237F5F5" : GetQueryStr("city");
    requestAreaInfo(country, city, false, false);
}
InitAreaInfo();

function requestAreaInfo(countryId, cityId, IsCountry, IsReload) {
    var _jsParam = new jsonRow();
    _jsParam = addNoAreStatistics(_jsParam, "车辆收索列表", "m0004")
    _jsParam.AddCell("ACTION", "init");
    _jsParam.AddCell("countryId", countryId);
    _jsParam.AddCell("cityId", cityId);
    ajaxComm(_jsParam, null, function () {
        initQueryParm(IsReload);
        if (IsCountry) {
            requestAreaInfo("", $("#citySel").val(), false, true);
            $("#city").val($("#citySel").val());
            $(".btn-home-search").click();
        }
    });
}